package com.zerui.manager.openplan.task;

import lombok.Getter;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @Author wh
 * @create_time 2023-06-28 14:56
 */
@Getter
public class OpenPlanDelayTask implements Delayed {
    private final Long planId;

    private final long delayTime;

    public OpenPlanDelayTask(Long planId, long delayTime) {
        this.planId = planId;
        // 延迟时间加当前时间
        this.delayTime =  delayTime;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(delayTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

	@Override
    public int compareTo(Delayed o) {
        return Long.compare(delayTime, ((OpenPlanDelayTask) o).delayTime);
    }
}
